#-------------------------------------------------------------------------------
# Name:        Error
# Purpose:
#
# Author:      Pablo
#
# Created:     13/03/2013
# Copyright:   (c) Monxcleyr Productions 2013
# Licence:     GPL v3
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import sys, pygame
import random
from ..gui import label

class Error():

  """Displays an error screen when the game crashes for whatever reason"""

  def __init__(self, message):
    self.message = str(message)
    pygame.init()
    self.size = self.width, self.height = 560, 240
    self.screen = pygame.display.set_mode(self.size)
    pygame.display.set_caption('Hj Engine has crashed.')


    self.errorlist = [\
    "If you're having crash problems, I feel bad for you son.",\
    "I got 99 problems and a crash ain't one.", \
    "Our crashes will fly from the aeroplane over the sea.",\
    "LOL CRASHED"]

    rand = random.randrange(len(self.errorlist))

    self.errormessage = self.errorlist[rand]

    self.font = pygame.font.Font('resources/fonts/error.ttf', 15)
    self.font2 = pygame.font.Font('resources/fonts/error.ttf', 20)
    pos1 = (self.width / 2, 50)
    self.label1 = label.Label(self.screen, self.errormessage, pos1, 'center', self.font, (255, 255, 0))
    self.label2 = label.Label(self.screen, 'See hj.log for details.', (self.width / 2, 150), 'center', self.font, (255,255,0))
    self.label3 = label.Label(self.screen, self.message, (self.width / 2, 100), 'center', self.font2, (255,255,0))



  def draw(self):

    print self.message

    while 1:
      for event in pygame.event.get():
        if event.type == pygame.QUIT:
          pygame.quit()
          sys.exit()

      self.screen.fill((97,97,97))


##      self.label1.draw()
      self.label2.draw()
      self.label3.draw()


      pygame.display.flip()
